package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.Location;
import com.camps.sdk.entity.LocationData;
import com.camps.sdk.utils.LocationUtils;

import java.util.List;

/**
 * @Author ldaoliang
 * @Date create in 15:58 2021/9/1
 * @Description
 */
public class AnalyzeQueryLocation implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData)
    {
        //*WT,800115470000876,V4,D1,170745,170747,A,2250.2266,N,11391.6154,E,0.11,356,460,11,0,1,30501,124968449,108,108,0,8,030621,FFFFDFFF
        //解密
        String[] split = parseCommand(originalData);
        String imei = split[1];
        String commandNumber = split[4];
        String latitude = split[7];
        String longitude = split[9];
        String speed = split[11];
        String orientation = split[12];
        String battery = split[22];
        String gpsNum = split[14];
/*        String deviceDate = split[split.length-2];
        String deviceStatus = split[split.length-1];*/
        String deviceDate = split[23];
        String deviceStatus = split[24];
        // mq传输对象
        Location location = new Location();
        location.setBattery(Integer.parseInt(battery));
        location.setDeviceDate(deviceDate);
        location.setCommandNumber(commandNumber);
        location.setImei(imei);
        location.setDeviceStatus(deviceStatus);
        location.setDeviceTime(commandNumber);
        LocationData mqLocationData = new LocationData();
        List<Double> list = LocationUtils.transiformLatAndLng(longitude, latitude);
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setGpsNum(Integer.parseInt(gpsNum));
        location.setLocationData(mqLocationData);
        return structureMessage(Constants.REPLY,Constants.CMD_QUERY_LOCATION,false,"",location);
    }
}
